# Contributor:
# Maintainer:
pkgname=rpm
pkgver=4.15.1
pkgrel=2
pkgdesc="Redhat Package Management utilities (RPM)"
url="https://www.rpm.org/"
arch="all"
license="GPL-2.0-or-later LGPL-2.0-or-later"
depends_dev="acl-dev binutils-dev bzip2-dev db-dev file-dev libarchive-dev
	libcap-dev nspr-dev nss-dev popt-dev xz-dev zlib-dev"
makedepends="$depends_dev gettext-dev graphviz py3-setuptools python3-dev
	zstd-dev automake autoconf libtool"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang py3-rpm:py_rpm"
source="http://ftp.rpm.org/releases/rpm-${pkgver%.*}.x/rpm-$pkgver.tar.bz2
	musl.patch
	"

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	_EXT_CPPFLAGS="-I/usr/include/nspr -I/usr/include/nss" \
	CFLAGS="$CFLAGS $_EXT_CPPFLAGS" CPPFLAGS="$CPPFLAGS $_EXT_CPPFLAGS" \
	LIBS="$LIBS -lintl" \
	PYTHON=python3 \
	./configure --prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--with-external-db \
		--with-cap \
		--with-acl \
		--without-lua \
		--enable-python \
		--enable-zstd=yes \
		--with-crypto=nss \
		--disable-plugins
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

py_rpm() {
	pkgdesc="Python3 bindings for RPM"

	replaces="py-rpm" # Backwards compatibility
	provides="py-rpm=$pkgver-r$pkgrel" # Backwards compatibility

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/python* "$subpkgdir"/usr/lib
}

sha512sums="6c66835da5a54349bcfba5cc69831c8c57568aabd53c5c2820ec78c361be5116fecd41777b097e9c49458f984a7beb054fa8ed453ff7263cad4a29a11f780767  rpm-4.15.1.tar.bz2
7972e9b129749b69b1c3b795cdc9981ff77e47954fe05f4885ce4d1b970eff4c0ad0393fa47ab43086dbfe7c0b7660b00860a978593da484aae514097e940868  musl.patch"
